//保存页面滚动条位置
export function saveScrollLocation () {
    window.onbeforeunload = function () {
        let scrollPos;
        if (typeof window.scrollY != 'undefined') {
            scrollPos = window.scrollY;
        } else if (typeof document.compatMode != 'undefined' &&
            document.compatMode != 'BackCompat') {
            scrollPos = document.documentElement.scrollTop;
        } else if (typeof document.body != 'undefined') {
            scrollPos = document.body.scrollTop;
        }
        //存储滚动条位置到cookies中
        document.cookie = "scrollTop=" + scrollPos;
    }
    if (document.cookie.match(/scrollTop=([^;]+)(;|$)/)) {
        //cookies中不为空，则读取滚动条位置
        let arr = document.cookie.match(/scrollTop=([^;]+)(;|$)/) || '';
        document.documentElement.scrollTop = parseInt(arr[1]);
        document.body.scrollTop = parseInt(arr[1]);
    }
}